<%@ Page language="vb" CodeFile="addDealer.aspx.vb" Inherits="addDealer_aspx_vb" %>

<%
    rowNumber = 0
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        Over()
        strJS = ""
        strJS = strJS + "[""countryID"", ""<1""],"
        strJS = strJS + "[""partnerID"", ""<1""],"
        strJS = strJS + "[""dealer"", ""==''""],"
        strJS = strJS + "[""city"", ""==''""]"
        checkFields()
        dbOpen()
        RecSet = Conn.Execute("Select partnerID, partnerName, countryID From tblPartner Order by partnerName")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                partnerID = RecSet.Fields("partnerID").Value
                partnerName = RecSet.Fields("partnerName").Value
                countryID = RecSet.Fields("countryID").Value
                strSelectSubJS = strSelectSubJS + "new Array(" & partnerID & "," & countryID & ",""" & partnerName & """),"
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select countryID From tblCountry Order by countryID")
        Do Until RecSet.EOF
            countryID = RecSet.Fields("countryID").Value
            strSelectSubJS = strSelectSubJS + "new Array(0," & countryID & ","" ------------------------------------  ""),"
            RecSet.MoveNext()
        Loop
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        strSelectSubJS = Left(strSelectSubJS, Len(strSelectSubJS) - 1)
        strSelectSubHeadline = "Select partner"
        selectSub()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>ADD CAR DEALER<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addDealer.aspx?do=save' method='post' name='store_productsSearch' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Country:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='countryID' id='countryID' onchange=""set_child_listbox(this, document.store_productsSearch.partnerID,Product,'Products');"">")
        Response.Write("<option value=''> Select country  ")
        dbOpen()
        RecSet = Conn.Execute("Select countryID, country From tblCountry")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                countryID = RecSet.Fields("countryID").Value
                country = RecSet.Fields("country").Value
                Response.Write("<option value='" & countryID & "'> " & country & " ")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_countryID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Partner:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='partnerID' id='partnerID' disabled>")
        Response.Write("<option value=''> - Select partner - ")
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_partnerID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td class='formBold'>Car dealer:</td><td align='right'><input type='text' name='dealer' id='dealer' size='40' maxlength='50'></td><td><div id='error_dealer' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'><input type='text' name='city' id='city' size='40' maxlength='50'></td><td><div id='error_city' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Areacode:</td><td align='right'><input type='text' name='areacode' id='areacode' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Telephone:</td><td align='right'><input type='text' name='telephone' id='telephone' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Email:</td><td align='right'><input type='text' name='email' id='email' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>STATISTIC<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select Count(dealerID) As dealerCount From tblDealer")
        If Not RecSet.EOF Then 
            dealerCount = RecSet.Fields("dealerCount").Value
            Response.Write("<tr bgcolor='#eeeeee'><td>Number of car dealers saved:</td><td align='right'>" & dealerCount & " st</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then 
        countryID = Request.Form("countryID")
        partnerID = Request.Form("partnerID")
        dealer = Request.Form("dealer")
        city = Request.Form("city")
        areacode = Request.Form("areaCode")
        telephone = Request.Form("telephone")
        email = Request.Form("email")
        userID = fragusLeasingUserID
        countryID = CLng(countryID)
        partnerID = CLng(partnerID)
        If Len(dealer) > 0 Then 
            dealer = Trim(dealer)
            dealer = Replace(dealer, "'", "")
            dealer = Replace(dealer, """", "")
            dealer = Replace(dealer, "<", "")
            dealer = Replace(dealer, ">", "")
            dealer = Replace(dealer, "=", "")
        End IF
        If Len(city) > 0 Then 
            city = Trim(city)
            city = Replace(city, "'", "")
            city = Replace(city, """", "")
            city = Replace(city, "<", "")
            city = Replace(city, ">", "")
            city = Replace(city, "=", "")
        End IF
        If Len(areacode) > 0 Then 
            areacode = Trim(areacode)
            areacode = Replace(areacode, "'", "")
            areacode = Replace(areacode, """", "")
            areacode = Replace(areacode, "<", "")
            areacode = Replace(areacode, ">", "")
            areacode = Replace(areacode, "=", "")
        End IF
        If Len(telephone) > 0 Then 
            telephone = Trim(telephone)
            telephone = Replace(telephone, "'", "")
            telephone = Replace(telephone, """", "")
            telephone = Replace(telephone, "<", "")
            telephone = Replace(telephone, ">", "")
            telephone = Replace(telephone, "=", "")
        End IF
        If Len(email) > 0 Then 
            email = Trim(email)
            email = Replace(email, "'", "")
            email = Replace(email, """", "")
            email = Replace(email, "<", "")
            email = Replace(email, ">", "")
            email = Replace(email, "=", "")
        End IF
        dbOpen()
        Conn.Execute("Insert Into tblDealer (userID, countryID, partnerID, dealer, city, areacode, telephone, email) Values(" & userID & "," & countryID & "," & partnerID & ",'" & dealer & "','" & city & "','" & areacode & "','" & telephone & "','" & email & "')")
        dbClose()
        Response.Redirect("addDealer.aspx?subDo=%20-%20SAVED")
    End IF
%>
